/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class Tan_cursoDAOImpl implements orm.dao.Tan_cursoDAO {
	public Tan_curso loadTan_cursoByORMID(int cu_id_curso) throws PersistentException {
		try {
			PersistentSession session = orm.AnotacionespowaPersistentManager.instance().getSession();
			return loadTan_cursoByORMID(session, cu_id_curso);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_curso getTan_cursoByORMID(int cu_id_curso) throws PersistentException {
		try {
			PersistentSession session = orm.AnotacionespowaPersistentManager.instance().getSession();
			return getTan_cursoByORMID(session, cu_id_curso);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_curso loadTan_cursoByORMID(int cu_id_curso, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.AnotacionespowaPersistentManager.instance().getSession();
			return loadTan_cursoByORMID(session, cu_id_curso, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_curso getTan_cursoByORMID(int cu_id_curso, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.AnotacionespowaPersistentManager.instance().getSession();
			return getTan_cursoByORMID(session, cu_id_curso, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_curso loadTan_cursoByORMID(PersistentSession session, int cu_id_curso) throws PersistentException {
		try {
			return (Tan_curso) session.load(orm.Tan_curso.class, new Integer(cu_id_curso));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_curso getTan_cursoByORMID(PersistentSession session, int cu_id_curso) throws PersistentException {
		try {
			return (Tan_curso) session.get(orm.Tan_curso.class, new Integer(cu_id_curso));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_curso loadTan_cursoByORMID(PersistentSession session, int cu_id_curso, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tan_curso) session.load(orm.Tan_curso.class, new Integer(cu_id_curso), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_curso getTan_cursoByORMID(PersistentSession session, int cu_id_curso, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tan_curso) session.get(orm.Tan_curso.class, new Integer(cu_id_curso), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_curso[] listTan_cursoByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.AnotacionespowaPersistentManager.instance().getSession();
			return listTan_cursoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_curso[] listTan_cursoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.AnotacionespowaPersistentManager.instance().getSession();
			return listTan_cursoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_curso[] listTan_cursoByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tan_curso as Tan_curso");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Tan_curso[]) list.toArray(new Tan_curso[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_curso[] listTan_cursoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tan_curso as Tan_curso");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Tan_curso[]) list.toArray(new Tan_curso[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_curso loadTan_cursoByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.AnotacionespowaPersistentManager.instance().getSession();
			return loadTan_cursoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_curso loadTan_cursoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.AnotacionespowaPersistentManager.instance().getSession();
			return loadTan_cursoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_curso loadTan_cursoByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Tan_curso[] tan_cursos = listTan_cursoByQuery(session, condition, orderBy);
		if (tan_cursos != null && tan_cursos.length > 0)
			return tan_cursos[0];
		else
			return null;
	}
	
	public Tan_curso loadTan_cursoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Tan_curso[] tan_cursos = listTan_cursoByQuery(session, condition, orderBy, lockMode);
		if (tan_cursos != null && tan_cursos.length > 0)
			return tan_cursos[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateTan_cursoByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.AnotacionespowaPersistentManager.instance().getSession();
			return iterateTan_cursoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTan_cursoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.AnotacionespowaPersistentManager.instance().getSession();
			return iterateTan_cursoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTan_cursoByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tan_curso as Tan_curso");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTan_cursoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tan_curso as Tan_curso");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_curso createTan_curso() {
		return new orm.Tan_curso();
	}
	
	public boolean save(orm.Tan_curso tan_curso) throws PersistentException {
		try {
			orm.AnotacionespowaPersistentManager.instance().saveObject(tan_curso);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Tan_curso tan_curso) throws PersistentException {
		try {
			orm.AnotacionespowaPersistentManager.instance().deleteObject(tan_curso);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Tan_curso tan_curso)throws PersistentException {
		try {
			orm.Tan_subsector[] lTan_subsectors = tan_curso.tan_subsector.toArray();
			for(int i = 0; i < lTan_subsectors.length; i++) {
				lTan_subsectors[i].setCu_id_curso(null);
			}
			orm.Tan_alumno[] lTan_alumnos = tan_curso.tan_alumno.toArray();
			for(int i = 0; i < lTan_alumnos.length; i++) {
				lTan_alumnos[i].setCu_id_curso(null);
			}
			return delete(tan_curso);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Tan_curso tan_curso, org.orm.PersistentSession session)throws PersistentException {
		try {
			orm.Tan_subsector[] lTan_subsectors = tan_curso.tan_subsector.toArray();
			for(int i = 0; i < lTan_subsectors.length; i++) {
				lTan_subsectors[i].setCu_id_curso(null);
			}
			orm.Tan_alumno[] lTan_alumnos = tan_curso.tan_alumno.toArray();
			for(int i = 0; i < lTan_alumnos.length; i++) {
				lTan_alumnos[i].setCu_id_curso(null);
			}
			try {
				session.delete(tan_curso);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Tan_curso tan_curso) throws PersistentException {
		try {
			orm.AnotacionespowaPersistentManager.instance().getSession().refresh(tan_curso);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Tan_curso tan_curso) throws PersistentException {
		try {
			orm.AnotacionespowaPersistentManager.instance().getSession().evict(tan_curso);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tan_curso loadTan_cursoByCriteria(Tan_cursoCriteria tan_cursoCriteria) {
		Tan_curso[] tan_cursos = listTan_cursoByCriteria(tan_cursoCriteria);
		if(tan_cursos == null || tan_cursos.length == 0) {
			return null;
		}
		return tan_cursos[0];
	}
	
	public Tan_curso[] listTan_cursoByCriteria(Tan_cursoCriteria tan_cursoCriteria) {
		return tan_cursoCriteria.listTan_curso();
	}
}
